package com.h3bpm.kumhosunny.crm.controller.reportfilter;

import OThinker.H3.Controller.ControllerBase;
import OThinker.H3.Entity.Reporting.ReportFilter;
import OThinker.H3.Entity.Reporting.ReportPage;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import data.DataTable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @authormi
 * @date2019/9/24
 */
@Controller
@RequestMapping("/Portal/CRM/ReportFilter")
public class ReportFilterController extends ControllerBase {


    @Override
    public String getFunctionCode() {
        return null;
    }

    @RequestMapping("/ReportFilterDefVal")
            public String  insertClearReportFilter (String arrayJson ,String reportCode,String returnUri){

        try {
            ReportPage report = getEngine().getReportManager().GetReportPage(reportCode);
            List<ReportFilter> filterList= null ;
            JSONArray array = JSONArray.parseArray(arrayJson);
            for(Object obj : array){
                JSONObject json = JSONObject.parseObject(obj.toString());

                filterList= report.getFilters();
                for(ReportFilter f : filterList){
                    if(f.getColumnCode().equals(json.getString("colCode"))) {
                        f.setFilterValue(json.getString("difaultV"));
                    }
                }

            }
            report.setFilters(filterList);
            getEngine().getReportManager().UpdateReportPage(report);
        } catch (Exception e) {
            e.printStackTrace();
        }





        return "redirect:"+returnUri;
    }
}
